home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MACD 5
/
MACD 5.bin
/
workbench
/
datatypes
/
playdt13.lha
/
PlayDT
/
PlayDT-src
/
UseCli.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-06-05
|
4KB
|
165 lines
/****************************************************************
*
* $VER: UseCli.c 1.3 (4.6.97) Tak Tang (tst92@ecs.soton.ac.uk)
*
* Copyright © 1997 Tak Tang
*
* You may use any part of this source code in your own programs
* provided that it is not called PlayDT.
*
******************************************************************
*
*/
/**** Soft definitions ****/
#define TEMPLATE "FILE/M,REQUESTER/S"
#define OPT_FILE 0
#define OPT_REQ 1
#define OPT_COUNT 2
/**** Header files ****/
#include "PlayDT.h"
#include <clib/dos_protos.h>
#include <clib/datatypes_protos.h>
#include <pragmas/dos_pragmas.h>
#include <pragmas/datatypes_pragmas.h>
#include <string.h>
/****** UseCLI *****************************************************
*
* NAME
* UseCLI - call PlayFile for each arg passed by cli, or call asl
*
* SYNOPSIS
* UseCLI ( GlobalData )
*
* UseCLI ( struct GlobalData * );
*
* FUNCTION
* UseCli attempts to play sound files specified on the command
* line. It accepts multiple arguments, each of which
* may be a pattern (eg #?.(8svx|wav) ). File names containing
* spaces must be enclosed in double quotes.
*
* If no files are specified, or if the REQUESTER switch is
* supplied, it will call the ASL file requester
*
* INPUTS
* GlobalData -
*
* RESULT
* None
*
* EXAMPLE
*
* NOTES
* Does not descend directories.
*
* BUGS
*
* SEE ALSO
* UseWB.c/UseWB(), UseASL.c/UseAsl(), PlayFile.c/PlayFile()
*
*****************************************************************************
*
*/
void UseCLI(struct GlobalData *gd)
{
ULONG opts[OPT_COUNT];
struct RDArgs *rdargs;
char *curarg, **argptr;
ULONG rc;
BPTR op, newlock, oldlock;
UBYTE errbuff[80];
struct AnchorPath __aligned ua;
/* parse command line */
memset (opts, 0, sizeof(opts));
rdargs = ReadArgs (TEMPLATE, (LONG *)opts, NULL);
if ( NULL!= rdargs )
{
if ( NULL != opts[OPT_FILE] )
{
/* for each argument ... */
argptr=(char **)opts[OPT_FILE];
while ( (curarg=*argptr++) && (FALSE==gd->UserStop))
{
memset(&ua, 0, sizeof(struct AnchorPath));
/* call pattern matching */
rc=MatchFirst(curarg, &ua);
/* for each match ... */
for ( ; (0==rc) && (FALSE==gd->UserStop) ; )
{
if (ua.ap_Info.fib_DirEntryType <0)
{
/* go to the directory */
newlock = DupLock(ua.ap_Current->an_Lock);
oldlock = CurrentDir(newlock);
/* play the file */
if ( 0!=PlayFile(gd, ua.ap_Info.fib_FileName) )
{
rc = IoErr();
} /* if PlayFile() OK */
CurrentDir(oldlock);
UnLock(newlock);
} /* if is file */
if (0==rc)
{
rc=MatchNext(&ua);
}
} /* while */
/* there was a problem, so tell the user */
if ( (rc != 0) &&
(rc != ERROR_NO_MORE_ENTRIES) &&
(rc != ERROR_BREAK) )
{
op = Output();
FPrintf(op,"%s: ", ua.ap_Info.fib_FileName);
if (rc >= DTERROR_UNKNOWN_DATATYPE)
{
FPrintf(op,GetDTString (rc), ua.ap_Info.fib_FileName);
}
else
{
Fault (rc, NULL, errbuff, sizeof (errbuff));
FPrintf(op,"%s",errbuff);
}
FPrintf(op,"\n");
} /* if */
MatchEnd(&ua);
} /* while arg++ */
} /* if opts[OPT_FILE] */
if ( (NULL == opts[OPT_FILE]) || (NULL!=opts[OPT_REQ]) )
{
UseASL(gd);
} /* if */
FreeArgs (rdargs);
} /* if NULL != rdargs */
else
{
PrintFault (IoErr(), MSG_FAILED);
} /* if NULL == rdargs */
} /* UseCLI */
/**** End of file ****/